/**
 * AtolCD/Spatialytics/widgets/DataDisplayer.js
 *
 * MDX query editor
 *
 * Copyright (C) 2010 Atol CD
 * See LICENSE file under this distribution for licensing information
 * 
 * @author Vincent Plantegenet
 * @since 201003
 **/

dojo.provide("AtolCD.Spatialytics.widgets.DataDisplayer");

dojo.require("GeoSOA.olap4js.Util");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dijit.TitlePane");
dojo.require("dijit.form.SimpleTextarea");
dojo.require("dijit.form.Button");

dojo.declare("AtolCD.Spatialytics.widgets.DataDisplayer",
		[dijit._Widget, dijit._Templated], {

	// title: String
	//	the title label
	title: "Informations",
	content: "",
	// --- private attributes:
	_observerFunc: null,
	_olapAjax: null,
	_solapContext: null,
	_currCellSet: null,
	// ---
	
	templatePath: dojo.moduleUrl("AtolCD.Spatialytics.widgets","templates/DataDisplayer.html"),
	widgetsInTemplate: true,

	// --- getters/setters
	
	_setTitleAttr: function (/*String*/ title) {
		this.title = title;
		this.titlePaneWidget.attr('title', this.title);
	},
	_setContentAttr: function (/*String*/ content) {
		this.content = content;
		this.titlePaneWidget.attr('content', this.content);
	},
	// ---
	
	
	// --- public methods
	
	//handling data displayer refresh
	getSolapObserver: function () {
		var that = this;
		var closure = function(SOLAP) {
		that._currCellSet = SOLAP.olapAjax.getCellSet();

		var informations = "";
		var selFeat = SOLAP.vectorLayer.selectedFeatures[0];
		var memberName = selFeat.attributes["memberName"];
		var memberVal = selFeat.attributes["value"];
		var axisOrd = selFeat.attributes["axisOrdinal"];
		var posOrd = selFeat.attributes["positionOrdinal"];
		var memOrd = selFeat.attributes["memberOrdinal"];

		informations += "<b>"+  that._currCellSet.axes[axisOrd].members[0][posOrd].name + " : </b><br>";

		for(var i in that._currCellSet.axes[0].members[0])  	
		{
			informations += "<b>"+  that._currCellSet.axes[0].members[0][i].name + ":</b> " + that._currCellSet.getCell([i,posOrd]) + "<br>";
		}

		that.titlePaneWidget.attr('content',informations);

		};
		
		return closure;
	},
	
	attachSOLAPContext: function (/*GeoSOA.Spatialytics.SOLAPContext*/ solapContext) {
		this._solapContext = solapContext;
		this._zoneObserverFunc = this.getSolapObserver();
		this._solapContext.onZoneChangeObservable.register(this._zoneObserverFunc);
	},
	
	detachSOLAPContext: function () {
		if (this._solapContext != null) {
			this._solapContext = null;
		}
	},
	
	// ---
	
});
